import HTMLParser
import urllib
import re


urlString="http://ape.nzix.net/peers.html"
check=False
urlText=[]

class ParseIXP(HTMLParser.HTMLParser):
    def handle_starttag(self,tag,attrs):
        global check
        if tag=="td":
            for name,value in attrs:
                if name=="style":
                    check=True
                    
    def handle_data(self,data):
        global check
        if data!='\n' and check==True:
            data=data.split()
            try:
                data=data[1]
                if(re.search("^[A][S]\d\d*$",data)):
                    number=data.replace("AS","")
                    urlText.append(number)
            except IndexError:
                pass
        check=False           
            
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())
filePath="ixp_members.txt"
file = open(filePath,"a")
for item in urlText:
    #print item
    print >> file, "64 %s" % item
file.close()